package com.buddy.summary.code.utils;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;


public class ImageUtil {

    public static int[] getHeightAndWidth(String imagePath) throws Exception {
        if (imagePath==null || "".equals(imagePath.trim())){
            throw new Exception("image path is null");
        }
        File file = new File(imagePath);
        return getHeightAndWidth(file);
    }

    public static int[] getHeightAndWidth(File file) throws Exception {
        if (!file.exists()){
            throw new Exception("image is not exist");
        }
        BufferedImage bufferImage = ImageIO.read(file);
        if (bufferImage == null){
            throw new Exception("can not read this image"+file.getPath());
        }
        int height = bufferImage.getHeight();
        int width = bufferImage.getWidth();
        int[] imageArr = {height,width};
        return imageArr;
    }
}
